package com.laiyima.zhongjiang.linghuilv.demo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.laiyima.zhongjiang.linghuilv.demo.R;
import com.laiyima.zhongjiang.linghuilv.demo.bean.IncomeBean;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;


public class IncomListAdapter extends BaseAdapter {
    private Context mContext;
    private LayoutInflater mInflater;
    private List<IncomeBean> mIncomeBean;
    private String TAG="IncomListAdapter";
    public IncomListAdapter(Context context, List<IncomeBean> mIncomeBeanDatas){
        mContext = context;
        mInflater = LayoutInflater.from(context);
        mIncomeBean = mIncomeBeanDatas;
    }

    @Override
    public int getCount() {
        return mIncomeBean.size();
    }

    @Override
    public Object getItem(int position) {
        return mIncomeBean.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if(viewHolder==null){
            convertView = mInflater.inflate(R.layout.income_item,parent,false);
            viewHolder = new ViewHolder();
            viewHolder.mName = convertView.findViewById(R.id.iC_name);
            viewHolder.mCtime = convertView.findViewById(R.id.iC_time);
            viewHolder.mWtype = convertView.findViewById(R.id.iC_type);
            viewHolder.mMoney = convertView.findViewById(R.id.iC_moeny);
            viewHolder.myimageView=convertView.findViewById(R.id.imcome_item_image);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        IncomeBean mTaxbean = mIncomeBean.get(position);
        viewHolder.mName.setText(mTaxbean.getAdmin_name());
        viewHolder.mCtime.setText(stampToDate(mTaxbean.getCreate_time()));
        viewHolder.mWtype.setText(mTaxbean.getWtype());
        String type=mTaxbean.getWtype();
        if(type.equals("积分返现")){
            viewHolder.myimageView.setImageResource(R.drawable.pd1);
        }else   if(type.equals("服务商收益")){
            viewHolder.myimageView.setImageResource(R.drawable.pd2);
        }else   if(type.equals("推广收益")){
            viewHolder.myimageView.setImageResource(R.drawable.pd4);
        }else   if(type.equals("积分兑换")){
            viewHolder.myimageView.setImageResource(R.drawable.pd5);
        }else if(type.equals("激活返现")){
            viewHolder.myimageView.setImageResource(R.drawable.pd6);
        }else {
            viewHolder.myimageView.setImageResource(R.drawable.pd7);
        }

        viewHolder.mMoney.setText(mTaxbean.getMoney());
        return convertView;
    }

    public static class ViewHolder{
        TextView mName;
        TextView mCtime;
        TextView mWtype;
        TextView mMoney;
        ImageView myimageView;
    }
    public static String stampToDate(String s){
        String res;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date(Long.parseLong(s+"000"));
        res = simpleDateFormat.format(date);
        return res;
    }

}
